package com.zhigh.project.tools;

import java.util.function.Function;

/**
 * 进行异常处理
 */
public interface RuntimeExceptions {

    static <R, OE extends Throwable, E extends RuntimeException> R wrapper(Executable<R, OE> executable, Function<Throwable, E> exApplier) throws E {
        try {
            return executable.execute();
        } catch (Throwable ex) {
            throw exApplier.apply(ex);
        }
    }

    static <OE extends Throwable, E extends RuntimeException> void wrapper(NonReturnExecutable<OE> executable, Function<Throwable, E> exApplier) throws E {
        try {
            executable.execute();
        } catch (Throwable ex) {
            throw exApplier.apply(ex);
        }
    }

    interface Executable<R, E extends Throwable> {
        R execute() throws E;
    }

    interface NonReturnExecutable<E extends Throwable> {
        void execute() throws E;
    }


}
